// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
module.exports = {
	_before: function () { // 通用预处理器

	},
	//壁纸标签相关函数  ny-wallpaper-tag
	// 添加壁纸时候输入标签专用
	async addwallpaperTag(item){
		const db = uniCloud.database();
		const collection = db.collection("ny-wallpaper-tag");
		let res = await collection.where({name:item}).get()
		let date = new Date().getTime()
		if(res.data.length==0){
			let rea = await collection.add({
				"name":item,
				"tag_cd":1,
				"cont":0,
				"create_date":date
			})
			return {
				code: 200,
				msg: '添加成功',
				data: rea
			}
		}else{
			return {
				code: 200,
				msg: '查询成功',
				data: res.data
			}
		}
		
	},
	// 获取指定标签
	async getwallpaperTag(){
		const db = uniCloud.database();
		const collection = db.collection("ny-wallpaper-tag");
		let res = await collection.where({"tag_cd":0}).orderBy("create_date", "asc").get()
		return {
			code: 200,
			msg: '查询成功',
			data: res.data
		}
	},
	// 获取所有标签
	async getwallpaperTagAll(){
		const db = uniCloud.database();
		const collection = db.collection("ny-wallpaper-tag");
		let res = await collection.orderBy("create_date", "asc").get()
		return {
			code: 200,
			msg: '查询成功',
			data: res.data
		}
	},
	// 修改标签
	async updatewallpaperTag(id,item){
		const db = uniCloud.database();
		const collection = db.collection("ny-wallpaper-tag");
		let res = collection.doc(id).update(item)
		return {
			code: 200,
			msg: '修改成功',
			data: res
		}
	}
	
}
